package com.hci.pwf;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class SearchActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search);
        
        final TextView tv01 = (TextView) super.findViewById(R.id.textview01);
        final TextView tv02=(TextView) super.findViewById(R.id.textview02);
        final TextView tv03=(TextView) super.findViewById(R.id.textview03);
        final TextView tv10 = (TextView) super.findViewById(R.id.TextView10);
        final TextView tv11 = (TextView) super.findViewById(R.id.TextView11);
        final TextView tv12 = (TextView) super.findViewById(R.id.TextView12);
        final TextView tv13 = (TextView) super.findViewById(R.id.TextView13);
        final TextView tv41 = (TextView) super.findViewById(R.id.TextView41);
        final TextView tv50 = (TextView) super.findViewById(R.id.TextView50);
        final TextView tv51 = (TextView) super.findViewById(R.id.TextView51);
        final TextView tv52 = (TextView) super.findViewById(R.id.TextView52);
        final TextView tv53 = (TextView) super.findViewById(R.id.TextView53);
        final TextView tv70 = (TextView) super.findViewById(R.id.TextView70);
        final TextView tv71 = (TextView) super.findViewById(R.id.TextView71);
        final TextView tv72 = (TextView) super.findViewById(R.id.TextView72);
        final TextView tv73 = (TextView) super.findViewById(R.id.TextView73);
		 
        final ImageView image14 = (ImageView) super.findViewById(R.id.ImageView14);
        final ImageView image60 = (ImageView) super.findViewById(R.id.ImageView60);
        final ImageView image61 = (ImageView) super.findViewById(R.id.ImageView61);
        final ImageView image62 = (ImageView) super.findViewById(R.id.ImageView62);
        final ImageView image63 = (ImageView) super.findViewById(R.id.ImageView63);
        
        final EditText et = (EditText)this.findViewById(R.id.textbox);
        final SearchWeather s = new SearchWeather();
        
        //press Enter to search the weather information
        Button b1=(Button)this.findViewById(R.id.Button01);
        b1.setOnClickListener(new Button.OnClickListener(){
    	     public void onClick(View v){
    	    	 ArrayList<WeatherInfo> list = new ArrayList<WeatherInfo>();
    	    	 try{
    	    	 if(et.getText()!=null){
    	    		 tv02.setText("Current Weather Information");
    	    		 tv03.setText("Forecast Weather Information");
    	    		 list = s.getWeather(et.getText().toString());
    	    		 s.display(list,tv01,tv10,tv11,tv12,tv13,tv41,tv50,tv51,tv52,tv53,tv70,tv71,tv72,tv73,image14,image60,image61,image62,image63);		
    	    	 }else{
    	    		 tv02.setText("");
    	    		 tv03.setText("");
    	    	 }
    	    	 }catch(Exception e){
    	    		 Log.e("WeatherError", "error");
    	    	 }
    	     }
        });
        
        //press Return to switch to the main screen
        /*
        Button b2=(Button)this.findViewById(R.id.Button02);
        b2.setOnClickListener(new Button.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				startActivity(new Intent(SearchActivity.this,MainActivity.class));
   		        finish();
			}
        	
        });
        */
    }
    
    

}